package com.boomsecret.threadtransfer;

import java.util.concurrent.TimeUnit;

/**
 * @author wangjinliang on 2019/1/31.
 */
public class InterruptedDemo {
    public static void main(String[] args) throws Exception {
        ThreadA threadA = new ThreadA();
        threadA.start();

        TimeUnit.SECONDS.sleep(2);

        // 如果抛出了InterruptedException异常 该标志就会被JVM重置为false
        threadA.interrupt();
    }

    public static class ThreadA extends Thread {
        @Override
        public void run() {
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("...");
            }
        }
    }
}
